<?php
$url = 'http://www.example.com';
function get_data($url){
//        $headers = array("Content-Type:text/html;charset=UTF-8", "Connection: Keep-Alive","appid:21222");
//      //初始化
//    $curl = curl_init();
//    //设置抓取的url
//    curl_setopt($curl, CURLOPT_URL, $url);
//    //设置头文件的信息作为数据流输出
//    curl_setopt($curl, CURLOPT_HEADER, 0);
//    //设置获取的信息以文件流的形式返回，而不是直接输出。
//    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0);
//
//    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//    //执行命令
//    $data = curl_exec($curl);
//    //关闭URL请求
//    curl_close($curl);
//    //显示获得的数据
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://api.cmburl.cn:8065/polypay/v1.0/mchorders/orderquery',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS => array('signResult' => '{"biz_content":"{\\"termId\\":\\"\\",\\"orderId\\":\\"AAA20200214AAABA91\\",\\"notifyUrl\\":\\"http://wlhost1.paas.cmbchina.cn/mch_notify/api/notify\\",\\"merId\\":\\"308999153310006\\",\\"payValidTime\\":\\"2400\\",\\"currencyCode\\":\\"156\\",\\"userId\\":null,\\"txnAmt\\":\\"1\\",\\"tradeScene\\":\\"OFFLINE\\",\\"body\\":\\"\\"}","encoding":"UTF-8","signMethod":"02","version":"0.0.1","sign":"MEQCIAFxrvGx4ZW9ErGIcnxj4aNztiiDf9UVYccrDjTbPbeYAiA+ui5m6xHh1lp8YCLOCrhTpy1TFuTgh2Ojwvy6YEH9sA=="}'),
        CURLOPT_HTTPHEADER => array(
            'appid: 77c248f7-cc64-4be0-a15b-2896b4ec7167',
            'timestamp: {{nowtime}}',
            'apisign: 89fbcf2691562645f3cd6acd9b484e4a'
        ),
    ));
    $response = curl_exec($curl);
    curl_close($curl);
    echo $response;
}
$key='567';
$authorization=55555;
get_data($url);
  die();


























$header = array('token:JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU','language:zh','region:GZ');
$content = array(
    'name' => 'fdipzone'
);
$response = tocurl($url, $header, $content);
$data = json_decode($response, true);
echo 'POST data:';
echo '<pre>';
print_r($data['post']);
echo '</pre>';
echo 'Header data:';
echo '<pre>';
print_r($data['header']);
echo '</pre>';
/**
 * 发送数据
 * @param String $url   请求的地址
 * @param Array $header 自定义的header数据
 * @param Array $content POST的数据
 * @return String
 */
function tocurl($url, $header, $content){
    $ch = curl_init();
    if(substr($url,0,5)=='https'){
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在
    }
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($content));
    $response = curl_exec($ch);
    if($error=curl_error($ch)){
        die($error);
    }
    curl_close($ch);
    return $response;
}
?>
